<?php	
class Archin_AjaxController extends Clu_Controller_Action_Hvn
{
	public function init()
	{
		$this->mService = new archin_Model_Service();
		parent::init();
	}

	public function orderAction()
	{
		$this->db = Zend_Db_Table::getDefaultAdapter();
		$type = $this->_request->getParam("type"); 	
		$order = $this->_request->getParam("nodeid");
		//$table = get_key("node_table_$type");
		if ($type == "people")
			$table = "people";
		if ($type == "project")
			$table = "projects";
		
		//now we have the order
		try {
			foreach ($order as $o => $id)
			{
				//update weight of user $id to be $order;
				$sql = sprintf("UPDATE `$table` SET `weight`=%d WHERE `id`=%d", $o, $id);
				$this->db->query($sql);	
//				die($sql);
			}
			$ret = array("success" => true, "data" => $order);
		}
		catch (Exception $e)
		{
			$ret = array("success" => false);
		}		
		$this->_helper->json->sendJson($ret);
	}
}
?>